package com.wushijia.net;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

/**
 * description:客户端
 *
 * @author yang
 * @date 2018/1/7 17:58
 */
public class Client {

  public static void main(String[] args) {
    String msg = "client data";

    try {
      Socket socket = new Socket("127.0.0.1", 8080);

      BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));

      PrintWriter printWriter = new PrintWriter(socket.getOutputStream());
      printWriter.println(msg);
      printWriter.flush();

      String line = in.readLine();
      System.out.println("received from server:" + line);

      printWriter.close();
      in.close();
      socket.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}
